using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ent.Voice.Nomination;

public partial class Controls_Feed : System.Web.UI.UserControl
{
    private int _entryId = -1;
    public int EntryId
    {
        get { return _entryId; }
        set { _entryId = value; }
    }
    private string _entryName = "";
    public string EntryName
    {
        get { return _entryName; }
        set { _entryName = value; }
    }
    private Vote _vote = new Vote();
    public Vote Vote
    {
        get { return _vote; }
        set { _vote = value; }
    }
    private bool _showButton = true;
    public bool ShowButton
    {
        get { return _showButton; }
        set { _showButton = value; }
    }
    private bool _center = true;
    public bool Center
    {
        get { return _center; }
        set { _center = value; }
    }
    public Controls_Feed()
    {
        this.PreRender += new EventHandler(Controls_Feed_PreRender);
    }

    void Controls_Feed_PreRender(object sender, EventArgs e)
    {
        cRate.JavaScript = "document.getElementById('" + rbPoints.ClientID + "').checked=true;";
        SetControls();
    }
    private void SetControls()
    {
        rbPoints.Text = "&nbsp;" + ResourceHelper.Get("LBL_Point");
        rbVote.Text = "&nbsp;" + ResourceHelper.Get("LBL_Vote");
        lblFeed.Text = ResourceHelper.Get("LBL_Feed");
        rbNone.Text = "&nbsp;" + ResourceHelper.Get("LBL_None");
        if (!_showButton)
            btnGo.Visible = false;
        else
        {
            SetJavascript();
            btnGo.Visible = true;
        }
        rbNone.Checked = true;
        switch (_vote.Option)
        { 
            case Option.None:
                rbNone.Checked = true;
                break;
            case Option.Vote:
                rbVote.Checked = true;
                break;
            case Option.Point:
                rbPoints.Checked = true;
                cRate.Value = _vote.Points;
                break;
        }
    }
    private void SetJavascript()
    {
        string jScript = "<script type=\"text/javascript\">";
        jScript += "function ShowRules() {";
        jScript += "\r\nvar sel='id=" + _entryId.ToString() + "&name=" + _entryName + "&sel=';";
        jScript += "\r\nif(document.getElementById('" + rbVote.ClientID + "').checked)";
        jScript += "\r\nsel+='2';";
        jScript += "\r\nelse if(document.getElementById('" + rbPoints.ClientID + "').checked)";
        jScript += "\r\n{";
        jScript += "\r\nsel+='3';";
        jScript += "\r\nsel+= '&pnt=' + document.getElementById('" + this.UniqueID + "$cRate_val').value;";
        jScript += "\r\n}";
        jScript += "\r\nelse";
        jScript += "\r\nsel+='1';";
        jScript += "\r\nvotewindow=dhtmlmodal.open('RuleSetBox', 'iframe', '" + ConfigurationManager.AppSettings["BaseUrl"] + "/ShowVote.aspx?' + sel, 'Vote Comments', 'width=560px,height=410px," + (Center ? "center=1" : "left=200,top=50") + ",resize=0,scrolling=0')";
        jScript += "\r\nreturn false;";
        jScript += "\r\n}";
        jScript += "\r\n</script>";
        Page.RegisterClientScriptBlock("script_name", jScript);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        imgFeed.Src = ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/feed.gif";

        btnGo.Src = ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/go.gif";
        btnGo.Attributes.Add("onmouseover", "javascript:this.src='" + ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/goh.gif'");
        btnGo.Attributes.Add("onmouseout", "javascript:this.src='" + ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/go.gif'");
    }
}
